package net.obviam.starassault.model;

import java.util.ArrayList;

import net.obviam.starassault.view.WorldRenderer;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;

public class Bob {

	public enum State {
		FIRE, WALKING, JUMPING, DYING, JUMPFIRE
	}
	
	public static final float SPEED = 4f;	// unit per second
	public static final float JUMP_VELOCITY = 4f;
	public static float SIZE = 0.1f; // half a unit
	private int score;
	private int finalscore;
	
	Vector2 	position = new Vector2();
	Vector2 	acceleration = new Vector2();
	Vector2 	velocity = new Vector2();
	Rectangle 	bounds;
	State		state = State.WALKING;
	float fireDelay;
	float timer = 0;
	boolean		facingLeft = true;


	public Bob(Vector2 position) {
		this.position = position;
		score = 0;
		finalscore = 0;
		fireDelay = 2000;
		bounds = new Rectangle(position.x, position.y, 0, 0);
	}

	
	public boolean isFacingLeft() {
		return facingLeft;
	}

	public void setFacingLeft(boolean facingLeft) {
		this.facingLeft = facingLeft;
	}
	
	public void incScore(){
		score++;
	}
	
	public void incFinalScore(){
		finalscore++;
	}
	
	public int getFinalScore(){
		return finalscore;
	}
	
	public void decScore(){
		score = score-10;
	}
	

	public void setScore(int s){
		score = s;
	}
	
	public int getScore(){
		return score;
	}
	
	public void updateSize(){
		float temp = (float) score/10000;
		this.SIZE = temp;
	}
	
	public Vector2 getPosition() {
		return position;
	}

	public Vector2 getAcceleration() {
		return acceleration;
	}

	public Vector2 getVelocity() {
		return velocity;
	}

	public Rectangle getBounds() {
		return bounds;
	}

	public State getState() {
		return state;
	}
	
	public void setState(State newState) {
		this.state = newState;
	}
	
	public void moveLeft(){
		position.add(0.15f, 0);
	}
	
	public void jump(){
		position.add(0, 0.1f);
	}
	 
	public void gravity(){
		position.add(0, -0.05f);
	}
	
	public void setBounds(float x, float y, float h, float w){
		bounds.x = x;
		bounds.y = y;
		bounds.height = h;
		bounds.width = w;
	}

	public void update(ArrayList<Bullet> list) {
		updateSize();
		moveLeft();
		gravity();
		if(state == state.JUMPING){
			jump();
			state = state.WALKING;
		}
		if(state == state.FIRE){
			list.add(new Bullet(this.position.x, this.position.y));
			decScore();
			state = state.WALKING;
		}
		if(state == state.JUMPFIRE){
			jump();
			list.add(new Bullet(this.position.x, this.position.y));
			decScore();
			state = state.WALKING;
		}
		incScore();
		incFinalScore();
	}
}
